﻿// Decompiled with JetBrains decompiler
// Type: LayersParser.Extensions.ListOfObjectsExtension
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using LayersParser.Interfaces;
using LayersParser.Objects;
using System.Collections.Generic;


namespace LayersParser.Extensions;

public static class ListOfObjectsExtension
{
  public static Param ReturningParameter(this List<Param> parameters, string name)
  {
    Param obj = new Param();
    foreach (Param parameter in parameters)
    {
      if (parameter.Name == name)
        obj = parameter;
    }
    obj.Name = name;
    return obj;
  }

  public static void RemoveParameter(this List<Param> parameters, string name)
  {
    int index = 0;
    while (index < parameters.Count)
    {
      if (parameters[index].Name == name)
        parameters.RemoveAt(index);
    }
  }

  public static void ReplaceParameter(this List<Param> parameters, Param newParam)
  {
    bool flag = false;
    for (int index = 0; index < parameters.Count; ++index)
    {
      if (parameters[index].Name == newParam.Name)
      {
        parameters[index] = newParam;
        flag = true;
      }
    }
    if (flag)
      return;
    parameters.Add(newParam);
  }

  public static List<string> ParToStr(this List<Param> parameters)
  {
    List<string> str = new List<string>();
    foreach (Param parameter in parameters)
      str.Add(parameter.Name);
    return str;
  }

  public static List<ICommand> ProcessToICommand(this List<Process> processes)
  {
    List<ICommand> icommand = new List<ICommand>();
    foreach (Process process in processes)
      icommand.Add((ICommand) process);
    return icommand;
  }

  public static List<Process> ICommandToProcess(this List<ICommand> icommands)
  {
    List<Process> process = new List<Process>();
    foreach (ICommand icommand in icommands)
      process.Add((Process) icommand);
    return process;
  }

  public static List<ICommand> CommandToICommand(this List<Command> commands)
  {
    List<ICommand> icommand = new List<ICommand>();
    foreach (Command command in commands)
      icommand.Add((ICommand) command);
    return icommand;
  }

  public static List<Command> ICommandToCommand(this List<ICommand> icommands)
  {
    List<Command> command = new List<Command>();
    foreach (ICommand icommand in icommands)
      command.Add((Command) icommand);
    return command;
  }

  public static Process ReturningProcess(this List<ICommand> processes, string name)
  {
    foreach (ICommand process in processes)
    {
      if (process.Name == name && process is Process)
        return (Process) process;
    }
    return (Process) null;
  }

  public static Command ReturningCommand(this List<ICommand> commands, string name)
  {
    foreach (ICommand command in commands)
    {
      if (command.Name == name)
        return (Command) command;
    }
    return (Command) null;
  }

  public static ICommand ReturningICommand(this List<ICommand> commands, string name, bool isOlp)
  {
    foreach (ICommand command in commands)
    {
      if (((!(command.Name == name) ? 0 : (!(command is Process) ? 1 : 0)) & (isOlp ? 1 : 0)) != 0 || command.Name == name && command is Process && !isOlp)
        return command;
    }
    return (ICommand) null;
  }

  public static bool ContainsMotion(this List<Motion> motions, int indexOfMotion)
  {
    foreach (Motion motion in motions)
    {
      if (motion.MotionType == indexOfMotion)
        return true;
    }
    return false;
  }
}
